# Maintainer: Sarah Ottinger

_realname=tabulate
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.8.7
pkgrel=2
pkgdesc='Pretty-print tabular data in Python, a library and a command-line utility. (mingw-w64)'
arch=('any')
url="https://bitbucket.org/astanin/python-tabulate"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose" "${MINGW_PACKAGE_PREFIX}-python-numpy" "${MINGW_PACKAGE_PREFIX}-python-pandas" "${MINGW_PACKAGE_PREFIX}-python-wcwidth")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-numpy: NumPy array support"
"${MINGW_PACKAGE_PREFIX}-python-pandas: pandas DataFrame support"
"${MINGW_PACKAGE_PREFIX}-python-wcwidth: wide-character support")
source=("https://files.pythonhosted.org/packages/source/${_realname:0:1}/${_realname//-/_}/${_realname//-/_}-${pkgver}.tar.gz")
sha256sums=('db2723a20d04bcda8522165c73eea7c300eda74e0ce852d9022e0159d7895007')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname//-/_}-$pkgver" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  
  local _PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/tabulate-script.py"
  
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -vDm 644 README.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/"
}
